package sharewithus.content.dao.cacheimpl.encoder;

import java.io.IOException;

import org.codehaus.jackson.JsonGenerationException;
import org.codehaus.jackson.JsonParseException;
import org.codehaus.jackson.map.JsonMappingException;
import org.codehaus.jackson.map.ObjectMapper;

import sharewithus.content.dto.Feed;


public class FeedEncoder extends AbstractBeanEnconder implements BeanEncoder<Feed>{
	
	public String getFrJson(Feed feed){
		byte[] b = null;
		String json = null;
		try {
			b  = mapper.writeValueAsBytes(feed);
			json = new String(b, JEDIS_CHARSET);
		} catch (JsonGenerationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (JsonMappingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return json;
		
	}
	
	public Feed parseJson(String json){
	
			Feed feed = null;
			try {
				feed = mapper.readValue(json, Feed.class);
			} catch (JsonParseException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (JsonMappingException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
	    	return feed; 
	}

	
	
}
